/*
 * @Author: ljkt
 * @Version: 2.0
 * @Date: 2021-10-18 16:10:15
 * @LastEditors: ljkt
 * @LastEditTime: 2025-01-27 19:49:56
 * @Description:
 */

#ifndef _DEV_HBRIDGE_H_
#define _DEV_HBRIDGE_H_

#define DEV_HBRIDGE_TASK_TIME (1UL)
#define DEV_HBRIDGE_SET_PWM(pwm) (gDev_HBrideg.Current_PwmDuty = pwm)
#define DEV_HBRIDGE_SET_DIR_PWM(dir, setduty) (gDev_HBrideg.Dir = dir, gDev_HBrideg.SetDuty = setduty)
#define H_BRIDGE_OFF REF_IO_LOW
#define H_BRIDGE_ON REF_IO_HIGH

enum
{
   e_INDEX_ENV_POSITION_OUT_WATER,
   e_INDEX_ENV_POSITION_IN_WATER,
   e_INDEX_ENV_POSITION_OVER_LOAD,
   e_INDEX_ENV_POSITION_MAX,
};

#define EVN_OUT_WATER_5S (1 << 0ul) // 水外5秒
#define EVN_IN_WATER_3S (1 << 2ul)  // 水中3秒
#define EVN_OVER_LOAD_3S (1 << 3ul) // 过载3秒

typedef struct
{
   unsigned char Dir;               // 0:正向 1:反向
   unsigned char Dir_Last;          // 上一次的方向
   signed char SetDuty;             // 0~100
   unsigned char Current_PwmDuty;   // 当前占空比
   signed short Pulse_mA;           // 脉冲电流值
   signed short Avg_mA;             // 平均值电流=脉冲电流??占空比
   unsigned char Evn_Position;      // 环境
   unsigned char Evn_Position_Last; // 上一次的环境
   unsigned char EVN_TIME;          // 环境+TIME
} s_dev_h_bridge;
extern Ram s_dev_h_bridge gDev_HBrideg;
void Dev_HBridge_Init(void);
void Dev_HBridge_Scan(void);
void Dev_HBridge_Write_Current_mA(signed short ma);
#endif
